﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using LitJson;
namespace BehaviorSystem
{
    [SerializeField]
    public class NodeData 
    {
        public  int Id { get; set; }
        public string NodeType { get; set; }

        public JsonData TaskData { get; set; }

        public List<NodeData> ChildNodes { get; set; }

        /// <summary>
        /// 序列化
        /// </summary>
        public JsonData Serialize()
        {
            JsonData data = new JsonData();
            data["NodeType"] = NodeType;
            data["TaskData"] = TaskData;
            data["ChildNodes"] = JsonUtility.ToJson(ChildNodes);
            data["Id"] = Id;
            return data;
        }

        public void DeSerialize(JsonData data)
        {
            NodeType = data["NodeType"].ToString();
            TaskData= data["TaskData"].ToString();
            Id = data["Id"].AsInt;
            ChildNodes = JsonMapper.ToObject<List<NodeData>>(data["ChildNodes"].ToJson());
            //for (int i = 0; i < ChildNodes.Count; i++)
            //{
            //    ChildNodes[i].DeSerialize(data["ChildNodes"][i]);

            //}
        }
    }
}

